package com.woniuxy.oldmanapi.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.oldmanapi.entity.Label;
import com.woniuxy.oldmanapi.entity.Older;
import com.woniuxy.oldmanapi.service.LabelService;
import com.woniuxy.oldmanapi.vo.ResponseResult;
import com.woniuxy.oldmanapi.xvo.OlderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LabelController {
    @Autowired
    LabelService labelService;

    //查询长者标签
    @GetMapping("/label/selectLabelByCons")
    public ResponseResult<PageInfo<Label>> selectLabelByCons(int now,int size,String labeltype){
        ResponseResult<PageInfo<Label>> result = new ResponseResult<>();
        try {
            PageInfo<Label> pageInfo = labelService.selectLabelByCons(now,size,labeltype);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }

    //修改长者标签
    @PostMapping("/label/updateLabel")
    public  ResponseResult<Void> updateLabel(@RequestBody Label label){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            labelService.updateLabel(label);
            result.setCode(200);
            result.setMsg("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
    //删除长者标签
    @PostMapping("/label/deleteLabel")
    public  ResponseResult<Void> deleteLabel(@RequestBody Label label){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            labelService.deleteLabel(label);
            result.setCode(200);
            result.setMsg("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
    //添加长者标签
    @PostMapping("/label/insertLabel")
    public  ResponseResult<Void> insertLabel(@RequestBody Label label){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            labelService.insertLabel(label);
            result.setCode(200);
            result.setMsg("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
}
